/*******************************************************************/
/*          VS1003 diriver for  Mega8 MP3 Player                   */
/*                                                                 */
/* Platform   : AVRStudio4.13 b528 + WinAVR20070122                */
/*              optimize -0s                                       */
/* Author     : bozai(Zhang Qibo)                                  */
/* E-mail     : sudazqb@163.com                                    */
/* MSN        : zhangqibo_1985@hotmail.com                         */
/* Date       : 2006-05-09                                         */
/*******************************************************************/
/*  20080101: modify codes for STM32F10x Cortex-M3 controller */
/*  20071208: modify codes for ARM platform (AT91SAM7S256)  */
/*2007-11-22: add bass tremble control                             */
/*2007-10-21: add new functions,                                   */
/*2007-10-19: use new delay function                               */
/*2007-05-04: add slow start up code, and add enough delay         */
/*2007-04-21:                                                      */

#ifndef __VS1003B_H__
#define __VS1003B_H__
#include <stm32f10x.h>

#define FFT_BANS_NUMBER		23

//#define CLOCK_REG       0xe000          // XTALI*4.5, 12.288*4.5 = 55.296, a bit higher than the maxmum frequency
#define CLOCK_REG       0xc3e8          //0xc00 is fow VS1003 or higher version


#define VS1003B_XCS			GPIO_Pin_12
#define VS1003B_XCS_PORT	GPIOB

#define VS1003B_XDCS		GPIO_Pin_6
#define VS1003B_XDCS_PORT	GPIOC

#define VS1003B_XRESET		GPIO_Pin_0
#define VS1003B_XRESET_PORT	GPIOE

#define VS1003B_CONTROL_SAME 0
#define VS1003B_CONTROL_PORT GPIOB	 /* it indicate that all above signal are in the same port*/

/*******************************/

#define VS1003B_DREQ		GPIO_Pin_7
#define VS1003B_DREQ_PORT	GPIOC

/*******************************/

#define VS1003B_SCK		GPIO_Pin_13
#define VS1003B_SCK_PORT	GPIOB

#define VS1003B_MISO		GPIO_Pin_14
#define VS1003B_MISO_PORT	GPIOB

#define VS1003B_MOSI		GPIO_Pin_15
#define VS1003B_MOSI_PORT	GPIOB

#define SPI2_NSS		GPIO_Pin_12
#define SPI2_NSS_PORT		GPIOB

#define VS1003B_SPI_SAME	0	/* it indicate that all SPI signal are in the same port*/
#define VS1003B_SPI_PORTS	GPIOB

#define VS1003B_GPIO_PORTS	RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOE

/********************************************************************************/

extern void VS1003B_WriteCMD(unsigned char addr, unsigned short dat);
extern unsigned char VS1003B_Init(void);	/* Initialization, include prot and chip config */
extern unsigned char VS1003B_SoftReset(void);		/* Software reset, clear decode time and jump out midi or wma playing*/
extern unsigned short VS1003B_ReadDecodeTime(void);	/* Get current decode time, for time display */
extern void VS1003B_Fill2048Zero(void);	/* fill 32bytes zero, for wma and midi zero filling */
extern void VS1003B_Write32B(unsigned char *buf);	/* write 32bytes data */
extern unsigned char VS1003B_NeedData(void);	/* Check if it need data */
extern void VS1003B_SetVolume(unsigned char vol); /* Set volume */
extern void VS1003_SetEQ(u16 EQ);
extern u16 GetHeadInfo(void);
extern u8 GetSpec(u16 *p);
extern void SetBands(u16 bands);
extern void ResetDecodeTime(void);
extern u16 GetDecodeTime(void);
void VS1003_INT_EXIT_ENABLE(void);
void VS1003_INT_EXIT_DISABLE(void);
void rt_hw_decoder_init(void);
void rt_hw_decoder_close(void);
/****************************************************************************************/
#endif
